<template>
    <div class="user">
        <PageTitle title="账号管理" addUrl="/admin/user/detail/none"></PageTitle>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column label="ID" prop="id"></el-table-column>
            <el-table-column label="账号" prop="username"></el-table-column>
            <el-table-column label="角色" prop="">
                <template slot-scope="scope">
                    {{scope.row.state == 2?'订单管理':'财务管理'}}
                </template>
            </el-table-column>
            <el-table-column label="创建日期" prop="create_at"></el-table-column>
            
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="page">
            <el-pagination
                layout="prev, pager, next"
                @current-change="handleCurrentChange"
                :current-page="current_page"
                :total="total_cont">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import PageTitle from '@/components/pageTitle/PageTitle.vue'
export default {
    components: {
        PageTitle,
    },
    data(){
        return{
            tableData:[],
            current_page:1,//当前页码
            total_cont:0,//数据总数目
        }
    },
    mounted(){
        this.getList()
    },
    methods:{
        //获取列表
        async getList(){
            let { data: { data, code, msg }} = await this.$axios({
                url: '/v1/goods/number',
                method: 'GET',
                params: {
                    size: 10,
                    page:this.current_page
                }
            })
                
            if(code == 0) {
                this.tableData = data.items
                this.total_cont = Number(data.page.totalCount)
            } else {
                this.$message.warning(data.message)
            }
        },
        //翻页
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.current_page = val
            this.getList()
        },
        //编辑
        handleEdit(index, row) {
            console.log(index, row);
        },
        //删除
        handleDelete(index, row) {
            console.log(index, row);
        }
    }
}
</script>
<style lang="scss" scoped>
    .page{
        text-align: center;
        margin: 20px auto;
    }
</style>